<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;

$(document).ready(function() {
listselectors();
});

function addhome() {
	var addhomeUrl = "/home/add/";
	var homeIdValue = $("#homeId").val();
	if(!checkInteger("家园编号",homeIdValue,false)) {
		return;
	}
	var homeIdParam = "homeId=" + xparseInt(homeIdValue);
		
	var cellIdValue = $("#cellId").val();
	if(!checkInteger("位置",cellIdValue,false)) {
		return;
	}
	var cellIdParam = "cellId=" + xparseInt(cellIdValue);
		
	var levelValue = $("#level").val();
	if(!checkInteger("等级",levelValue,false)) {
		return;
	}
	var levelParam = "level=" + xparseInt(levelValue);
		
	var cardIdValue = $("#cardId").val();
	
	var cardIdParam = "cardId=" + cardIdValue;
		
	var taskIdValue = $("#taskId").val();
	
	var taskIdParam = "taskId=" + taskIdValue;
		
	var homeresValue = $("#homeres").val();
	
	var homeresParam = "homeres=" + homeresValue;
			
	$.ajax({
		   type: "POST",
		   url: addhomeUrl,
		   data:   homeIdParam +'&'+ cellIdParam +'&'+ levelParam +'&'+ cardIdParam +'&'+ taskIdParam +'&'+ homeresParam ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			       window.returnValue=1;
			       beforeWindowClose();
				   window.close();
			   }else {
				  errDialog(data.message);
			   }
		   }
	});
}

function listselectors() {
}

function addcardId() {
	var cardIdstr = $("#cardId").val();
	var returnCallback = function(retvalue) {
		$('#cardId').val(retvalue);
	}
	openDialog("/pages/core/SelectorArray.html",["Card","Card",cardIdstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
}
function addtaskId() {
	var taskIdstr = $("#taskId").val();
	var returnCallback = function(retvalue) {
		$('#taskId').val(retvalue);
	}
	openDialog("/pages/core/SelectorArray.html",["Task","Task",taskIdstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
}

function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("home",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/home/add" method="post">
		<table>
			<tbody>				
					<tr>					<td>
						<label for="homeId" id="lbl_homeId">家园编号</label>
													<input type="text" id="homeId" name="homeId" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="cellId" id="lbl_cellId">位置</label>
													<input type="text" id="cellId" name="cellId" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="level" id="lbl_level">等级</label>
													<input type="text" id="level" name="level" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="cardId" id="lbl_cardId">对应图鉴</label>
													<input type="text" id="cardId" name="cardId" value="[]" disabled/>
							<input type="button" value="..." onclick="addcardId()"/>
											</td>
					</tr>				
					<tr>					<td>
						<label for="taskId" id="lbl_taskId">对应任务</label>
													<input type="text" id="taskId" name="taskId" value="[]" disabled/>
							<input type="button" value="..." onclick="addtaskId()"/>
											</td>
									
										<td>
						<label for="homeres" id="lbl_homeres">家园资源</label>
													<input type="text" id="homeres" name="homeres" disabled/>
							<input type="button" value="..." onclick="openResource('homeres','')"/><span class="tips">[资源]</span>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="addhome()" value="添加"/>
	</form>
	</div>
</body>